unit borda;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, DBTables;

type
  TFormBorda = class(TForm)
    QueryBorda: TQuery;
    DataSource1: TDataSource;
    DBGridBorda: TDBGrid;
    BitBtn1: TBitBtn;
    QueryBordanm: TStringField;
    QueryBordavl_borda: TFloatField;
    UpdateSQL1: TUpdateSQL;
    QueryAux: TQuery;
    QueryBordaid: TIntegerField;
    procedure QueryBordavl_bordaGetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBGridBordaKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormBorda: TFormBorda;

implementation

{$R *.dfm}

procedure TFormBorda.QueryBordavl_bordaGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
try
 StrtoFloat(Trim(QueryBorda.fieldByName('vl_borda').AsString));
 Text := formatfloat('###,###,##0.00', StrToFloat(QueryBorda.fieldByName('vl_borda').AsString));
except
 abort;
end;
end;

procedure TFormBorda.BitBtn1Click(Sender: TObject);
begin
close;
end;

procedure TFormBorda.FormShow(Sender: TObject);
begin
    QueryBorda.Open;
    DBGridBorda.SelectedIndex := 1;

end;

procedure TFormBorda.DBGridBordaKeyPress(Sender: TObject; var Key: Char);
var sql : string;
begin


    if key = #13 then
    begin

        sql := 'update borda set vl_borda = ' + DBGridBorda.SelectedField.Text  +
                   ' where id = ' + QueryBorda.fieldByName('id').AsString;

        QueryAux.SQL.Clear;
        QueryAux.SQL.Add(sql);
        QueryAux.ExecSQL;

        QueryBorda.Next;

    end;


end;

end.
